//
//  HYMovieMoreViewController.m
//  KaiJing
//
//  Created by lanou on 16/1/14.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "HYMovieMoreViewController.h"
#import "HYSalonViewController.h"
#import "HYShadowViewController.h"
#import "HYShortViewController.h"
#import "HYShowViewController.h"
#import "HYOriginalViewController.h"
#import "HYMovieMoreCollectionViewCell.h"
@interface HYMovieMoreViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) HYSalonViewController *salonVC;
@property (nonatomic, strong) HYShadowViewController *shadowVC;
@property (nonatomic, strong) HYShortViewController *shortVC;
@property (nonatomic, strong) HYShowViewController *showVC;
@property (nonatomic, strong) HYOriginalViewController *originalVC;
@property (nonatomic, strong) NSArray *titleArray;

@end

static NSString *identifier = @"HYMovieMoreViewController";
@implementation HYMovieMoreViewController


- (void) setUpData {
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kRandomClolor;
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:(UIBarButtonItemStylePlain) target:self action:@selector(leftButton)];
    self.navigationItem.leftBarButtonItem = leftButton;
    [self creatChildViewController];
    _titleArray = @[@"短片",@"影单",@"沙龙",@"电影原声"];
    

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    // 设置集合视图为横向滚动
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    // 创建集合视图
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30) collectionViewLayout:layout];
    collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    // 隐藏掉横向滚动条
    collectionView.showsHorizontalScrollIndicator = NO;
    // 注册自定义cell类
    [collectionView registerClass:[HYMovieMoreCollectionViewCell class] forCellWithReuseIdentifier:identifier];
    
    [self.view addSubview:collectionView];
    
    
}

#pragma mark --添加子式图控制器--
- (void)creatChildViewController {
    //上映
    _showVC = [[HYShowViewController alloc] init];
    [self addChildViewController:_showVC];
    [self.view addSubview:_showVC.view];
    
//    短片
    _shortVC = [[HYShortViewController alloc] init];

    //影单
    _shadowVC = [[HYShadowViewController alloc] init];

    
    //沙龙
    _salonVC = [[HYSalonViewController alloc] init];


    //电影原声
    _originalVC = [[HYOriginalViewController alloc] init];
    
    

    
}

- (void)leftButton {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark --- 返回分区 ---
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

#pragma mark --- 返回item个数 ---
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _titleArray.count;
}

#pragma mark --- 返回cell ---
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HYMovieMoreCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    cell.title.text = _titleArray[indexPath.row];
       return cell;
}

#pragma mark --- 返回item大小 ---
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(kScreenWidth /4, 30);
}

#pragma mark --点击item触发方法--
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    switch (indexPath.row) {
        case 0:
            
           [self.navigationController pushViewController:_shortVC animated:YES];
            break;
            
            case 1:
            [self.navigationController pushViewController:_shadowVC animated:YES];
            break;
            
            case 2:
            [self.navigationController pushViewController:_salonVC animated:YES];
            break;
            
            case 3:
            [self.navigationController pushViewController:_originalVC animated:YES];
            break;
            
            default:
            break;
    }
    
    
}

@end
